package com.zxx.pattern.buildPattern.build_book;


import com.zxx.yuanze.ocp.answer.DoubleCache;

/**
 * @author zxx on 2020/12/16
 */
public final class ImageLoader {

    //线程池数量为CPU数量
    //ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
    private ImageLoaderConfig mConfig;

    //单例省略


    public void init(ImageLoaderConfig config) {
        mConfig = config;
        //检测配置的合法性,并根据配置做一些初始化操作
        checkConfig();
        //省略
    }

    private void checkConfig() {

    }

//    public void display(String imgUrl, ImageView imageView) {
//        Bitmap bitmap = mConfig.imageCache.get(imgUrl);
//        if (bitmap != null) {
//            imageView.setImageBitmap(bitmap);
//            return;
//        }
//        //提交图片加载请求
//        submitLoadRequest(imgUrl, imageView);
//    }
//
//    private void submitLoadRequest(final String imgUrl, final ImageView imageView) {
//        //省略
//    }

//    private Bitmap downloadImage(String imgUrl) {
//        Bitmap bitmap = null;
//        //省略下载代码
//        return null;
//    }


    //使用
    public void initImageLoader(){
        ImageLoaderConfig config = new ImageLoaderConfig.Builder()
                //.setLoadingPlaceHolder(R.id.loading)
                //.setErrorPlaceHolder(R.id.error)
                .setImageCache(new DoubleCache())
                .setThreadCount(4)
                .create();

        //ImageLoader.getInstance().init(config);
    }

}
